import {Component, OnInit} from '@angular/core';
import {ElasticSearchService} from "../../../shared/service/es/elastic-search.service";
import * as _ from "lodash";

@Component({
  selector: 'app-roles',
  templateUrl: './roles.component.html',
  styleUrls: ['./roles.component.scss']
})
export class RolesComponent implements OnInit {
  result: any[] = []

  constructor(
    private es: ElasticSearchService,
  ) {
  }

  ngOnInit(): void {
    this.search()
  }

  search() {
    this.es.getRequest(`/_security/role`).subscribe(r => {
      let result = _.toPairs(r)
      result = _.map(result, (v) => {
        v[1].indexNames = []
        for (let index of v[1].indices) {
          for (let name of index[`names`]) {
            v[1].indexNames.push(name)
          }
        }
        return v;
      })
      this.result = result
      console.log(this.result)
    })
  }

  details(username: string) {
    console.log(username)
  }
}
